﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Game.Kernel;
using Game.Entity.Accounts;
using Game.Entity.Treasure;
using Game.Facade;
using Game.Utils;
using System.Text;

namespace Game.Web.UserService
{
    public partial class PropertyUseRecord : System.Web.UI.Page
    {
        public UserTicketInfo user = null;
        protected void Page_Load(object sender, EventArgs e)
        {
            //判断是否登录
            if(!Fetch.IsUserOnline())
            {
                return;
            }
            user = Fetch.GetUserCookie();

            if(!IsPostBack)
            {
                DataBindRecord();
            }
        }

        /// <summary>
        /// 绑定查询数据
        /// </summary>
        private void DataBindRecord()
        {
            int sPageIndex = GameRequest.GetQueryInt("page", 1);
            int sPageSize = anpPage.PageSize;

            PagerSet pagerSet = FacadeManage.aideRecordFacade.GetRecordUseProperty(user.UserID, sPageIndex, sPageSize);
            anpPage.RecordCount = pagerSet.RecordCount;

            if(pagerSet.PageSet.Tables[0].Rows.Count > 0)
            {
                rptInsureList.DataSource = pagerSet.PageSet;
                rptInsureList.DataBind();

                this.rptInsureList.Visible = true;
                this.litNoData.Visible = false;
            }
            else
            {
                this.rptInsureList.Visible = false;
                this.litNoData.Visible = true;
            }
        }

        /// <summary>
        /// 根据用户ID获取gameid
        /// </summary>
        /// <param name="userID"></param>
        /// <returns></returns>
        public string GetGameIDByUserID(int userID)
        {
            int gameid = FacadeManage.aideAccountsFacade.GetGameIDByUserID(userID);
            return gameid == 0 ? user.GameID.ToString() : gameid.ToString();
        }
        /// <summary>
        /// 根据道具标识获取道具名
        /// </summary>
        /// <param name="propertyId"></param>
        /// <returns></returns>
        public string GetPropertyName(int propertyId)
        {
            Game.Entity.Platform.GameProperty prop = FacadeManage.aidePlatformFacade.GetGameProperty(propertyId);
            return prop != null ? prop.Name : "";
        }
    }
}